package com.fast.develop.meta.dm.factory;

import com.fast.develop.meta.dm.builder.MetaFieldBuilder;
import com.fast.develop.meta.dm.enums.BasicFieldType;
import com.fast.develop.meta.dm.field.FieldCatelog;
import com.fast.develop.meta.dm.field.catalog.*;
import org.json.JSONObject;

/**
 * @author 莫寅
 * @createTime 2022-06-04 15:58
 * @desc：
 */
public class TypeFactory{

    public static FieldCatelog create(String catalog, JSONObject rawSchema, MetaFieldBuilder metaFieldBuilder){
        FieldCatelog fieldType = null;
        String type = rawSchema.optString("type", null);
        switch (catalog){
            case "basic":
                fieldType = new BasicCatalog();
                ((BasicCatalog) fieldType).setBasicFieldType(BasicFieldType.create(type));
                break;
            case "dd":
                fieldType = new DdCatalog();
                ((DdCatalog) fieldType).setType(type);
                break;
            case "mdm":
                fieldType = new MdmCatalog();
                ((MdmCatalog) fieldType).setType(type);
                break;
            case "relation":
                fieldType = new RelationCatalog();
                RelationCatalog relationMode = (RelationCatalog) fieldType;
                relationMode.setType(RelationCatalog.Relation.valueOf(type));
                break;
            case "vo":
                fieldType = new VoCatalog();
                ((VoCatalog) fieldType).setType(type);
                break;
        }

        return fieldType;
    }
}
